#include <vector>
using std::vector;
class Solution {
public:
    int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
        vector<vector<int>>dp(obstacleGrid.size(),vector<int>(obstacleGrid.front().size(),0));
        dp[0][0]=1;
        for(int i=0;i<dp.size();i++){
            for(int j=0;j<dp[i].size();j++){
                if(obstacleGrid[i][j])dp[i][j]=0;
                else{
                    dp[i][j]+=(i-1>=0)?dp[i-1][j]:0;
                    dp[i][j]+=(j-1>=0)?dp[i][j-1]:0;
                }
            }
        }
        return dp.back().back();
    }
};